package com.oracle.common.utils;

public class R<T> {
    private int code;   //状态码
    private String msg; //响应信息
    private T data;     //响应数据

    /**
     * 响应失败
     * @param t
     * @return
     */
    public static<T> R failed(T t){
        R R = new R(ResEnum.failed.getCode(), ResEnum.failed.getMsg());
        R.setData(t);
        return R;
    }

    /**
     * 响应成功
     * @param
     * @return
     */
    public static<T> R ok(){
        R R = new R(ResEnum.success.getCode(), ResEnum.success.getMsg());
        R.setData(null);
        return R;
    }
    /**
     * 响应成功
     * @param t
     * @return
     */
    public static<T> R ok(T t){
        R R = new R(ResEnum.success.getCode(), ResEnum.success.getMsg());
        R.setData(t);
        return R;
    }

    public R() {
    }

    public R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
